//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ForwardMeasureProcess1D.h"
using namespace Cephei::QL::Processes;
#include <gen/QL/Math/Array.h>
#include <gen/QL/StochasticProcess1D.h>
using namespace Cephei::QL::Math;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (boost::shared_ptr<QuantLib::ForwardMeasureProcess1D>& childNative, Object^ owner) : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
#ifdef HANDLE
	_phForwardMeasureProcess1D = NULL;
#endif
	_ppForwardMeasureProcess1D = &childNative;
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppForwardMeasureProcess1D));
}
Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (QuantLib::ForwardMeasureProcess1D& childNative, Object^ owner) : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
#ifdef HANDLE
	_phForwardMeasureProcess1D = NULL;
#endif
	_ppForwardMeasureProcess1D = new boost::shared_ptr<QuantLib::ForwardMeasureProcess1D> (&childNative);
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppForwardMeasureProcess1D));
    _ForwardMeasureProcess1DOwner = owner;
    _StochasticProcess1DOwner = owner;
}

Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (CForwardMeasureProcess1D^ copy) : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
#ifdef HANDLE
	_phForwardMeasureProcess1D = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppForwardMeasureProcess1D = new boost::shared_ptr<QuantLib::ForwardMeasureProcess1D> (copy->GetShared());
        _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppForwardMeasureProcess1D));
    }
}
Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (System::Type^ t) : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
#ifdef HANDLE
	_phForwardMeasureProcess1D = NULL;
#endif
	if (!t->IsSubclassOf(CForwardMeasureProcess1D::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (QuantLib::Handle<QuantLib::ForwardMeasureProcess1D>& childNative, Object^ owner)  : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
	_phForwardMeasureProcess1D = &childNative;
	_ppForwardMeasureProcess1D = &static_cast<boost::shared_ptr<QuantLib::ForwardMeasureProcess1D>>(childNative.currentLink());
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppForwardMeasureProcess1D));
    _ForwardMeasureProcess1DOwner = owner;
}
Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (QuantLib::Handle<QuantLib::ForwardMeasureProcess1D> childNative)  : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
	_phForwardMeasureProcess1D = &childNative;
	_ppForwardMeasureProcess1D = &static_cast<boost::shared_ptr<QuantLib::ForwardMeasureProcess1D>>(childNative.currentLink());
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppForwardMeasureProcess1D));
}
#endif
#ifdef STRUCT
Cephei::QL::Processes::CForwardMeasureProcess1D::CForwardMeasureProcess1D (QuantLib::ForwardMeasureProcess1D childNative)  : CStochasticProcess1D(CForwardMeasureProcess1D::typeid)
{
#ifdef HANDLE
	_phForwardMeasureProcess1D = NULL;
#endif
	_ppForwardMeasureProcess1D = new boost::shared_ptr<QuantLib::ForwardMeasureProcess1D> (new QuantLib::ForwardMeasureProcess1D (childNative));
    _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (boost::dynamic_pointer_cast<QuantLib::StochasticProcess1D> (*_ppForwardMeasureProcess1D));
}
#endif

Cephei::QL::Processes::CForwardMeasureProcess1D::~CForwardMeasureProcess1D ()
{
    if (_ppForwardMeasureProcess1D != NULL)
    {
	    delete _ppForwardMeasureProcess1D;
        _ppForwardMeasureProcess1D = NULL;
    }
}
Cephei::QL::Processes::CForwardMeasureProcess1D::!CForwardMeasureProcess1D ()
{
    if (_ppForwardMeasureProcess1D != NULL)
    {
	    delete _ppForwardMeasureProcess1D;
    }
}
QuantLib::ForwardMeasureProcess1D& Cephei::QL::Processes::CForwardMeasureProcess1D::GetReference ()
{
    if (_ppForwardMeasureProcess1D == NULL) throw gcnew NativeNullException ();
	return **_ppForwardMeasureProcess1D;
}
boost::shared_ptr<QuantLib::ForwardMeasureProcess1D>& Cephei::QL::Processes::CForwardMeasureProcess1D::GetShared ()
{
    if (_ppForwardMeasureProcess1D == NULL) throw gcnew NativeNullException ();
	return *_ppForwardMeasureProcess1D;
}
QuantLib::ForwardMeasureProcess1D* Cephei::QL::Processes::CForwardMeasureProcess1D::GetPointer ()
{
    if (_ppForwardMeasureProcess1D == NULL) throw gcnew NativeNullException ();
	return &**_ppForwardMeasureProcess1D;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ForwardMeasureProcess1D>& Cephei::QL::Processes::CForwardMeasureProcess1D::GetHandle ()
{
	if (_phForwardMeasureProcess1D == NULL)
	{
		_phForwardMeasureProcess1D = new Handle<QuantLib::ForwardMeasureProcess1D> (*_ppForwardMeasureProcess1D);
	}
	return *_phForwardMeasureProcess1D;
}
#endif
bool Cephei::QL::Processes::CForwardMeasureProcess1D::HasNative () 
{
	return (_ppForwardMeasureProcess1D != NULL);
}

Double Cephei::QL::Processes::CForwardMeasureProcess1D::GetForwardMeasureTime::get ()
{
    try
    {
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppForwardMeasureProcess1D)->getForwardMeasureTime ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Processes::IForwardMeasureProcess1D^ Cephei::QL::Processes::CForwardMeasureProcess1D::SetForwardMeasureTime (Double T)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Time _T = (QuantLib::Time)ValueHelper::Convert (T);
    	(*_ppForwardMeasureProcess1D)->setForwardMeasureTime ( _T );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

